package com.situ.day6;

//封装
public class Student {
    //属性私有private类的外部就不能直接访问
    private int id;
    private String name;
    private int age;
    private String gender;

    //构造方法
    //无参构造方法
    public Student() {
        System.out.println("Student.Student");
    }

    //有参构造方法
    public Student(int id, String name, int age, String gender) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    //属性私有，然后通过public的get和set方法间接访问私有的属性
    public void setId(int id) {
        //The value id assigned to 'id' is never used
        //Variable is already assigned to this value
        //就近原则
        //id = id;
        //this代表当前对象
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setAge(int age) {
        if (age >= 0 && age <= 120) {
            this.age = age;
        }
    }

    public int getAge() {
        return age;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getGender() {
        return gender;
    }

    public void study() {
        //System.out.println("年龄是23的张三正在学习");
        System.out.println("年龄是"+age+"的"+name+"正在学习");
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                '}';
    }
}
